package com.flowershop.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.flowershop.entity.Employee;
import com.flowershop.mapper.EmployeeMapper;
import com.flowershop.service.EmployeeService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, Employee> implements EmployeeService {
    
    @Override
    public Employee login(String username, String password) {
        log.info("尝试登录 - 用户名: {}", username);
        
        // 1. 根据用户名查询
        LambdaQueryWrapper<Employee> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Employee::getUsername, username);
        Employee employee = this.getOne(queryWrapper);
        
        if (employee == null) {
            log.info("登录失败 - 用户名不存在: {}", username);
            return null;
        }
        
        log.info("找到用户 - ID: {}, 用户名: {}, 存储的密码: {}", employee.getId(), employee.getUsername(), employee.getPassword());
        
        // 2. 验证密码
        if (password.equals(employee.getPassword())) {
            log.info("登录成功 - 用户名: {}", username);
            employee.setPassword(null);
            return employee;
        }
        
        log.info("登录失败 - 密码不匹配 - 用户名: {}, 输入的密码: {}, 正确的密码: {}", username, password, employee.getPassword());
        return null;
    }
} 